package com.ruoyi.delivery.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.delivery.mapper.GarbageRecyclingDetailOrderMapper;
import com.ruoyi.domain.GarbageRecyclingDetailOrder;
import com.ruoyi.domain.GarbageRecyclingOrder;
import com.ruoyi.domain.tools.JiFenJiSuan;
import com.ruoyi.domain.tools.SuiJiId;
import io.seata.common.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.delivery.mapper.GarbageRecyclingOrderMapper;
import com.ruoyi.delivery.service.IGarbageRecyclingOrderService;

/**
 * 垃圾回收订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-29
 */
@Service
public class GarbageRecyclingOrderServiceImpl implements IGarbageRecyclingOrderService 
{
    @Autowired
    private GarbageRecyclingOrderMapper garbageRecyclingOrderMapper;
    @Autowired
    private GarbageRecyclingDetailOrderMapper garbageRecyclingDetailOrderMapper;

    /**
     * 查询垃圾回收订单
     * 
     * @param orderid 垃圾回收订单ID
     * @return 垃圾回收订单
     */
    @Override
    public GarbageRecyclingOrder selectGarbageRecyclingOrderById(Long orderid)
    {
        return garbageRecyclingOrderMapper.selectGarbageRecyclingOrderById(orderid);
    }

    /**
     * 查询垃圾回收订单列表
     * 
     * @param garbageRecyclingOrder 垃圾回收订单
     * @return 垃圾回收订单
     */
    @Override
    public List<GarbageRecyclingOrder> selectGarbageRecyclingOrderList(GarbageRecyclingOrder garbageRecyclingOrder)
    {
        return garbageRecyclingOrderMapper.selectGarbageRecyclingOrderList(garbageRecyclingOrder);
    }

    /**
     * 新增垃圾回收订单
     * 
     * @param garbageRecyclingOrder 垃圾回收订单
     * @return 结果
     */
    @Override
    public int insertGarbageRecyclingOrder(GarbageRecyclingOrder garbageRecyclingOrder)
    {
        //给查询垃圾回收订单实体类赋值
        //生成订单编号
        SuiJiId suiJiId = new SuiJiId();
        garbageRecyclingOrder.setOrderid(suiJiId.getOrderId());
        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String str = simpleDateFormat.format(date);
        garbageRecyclingOrder.setDelivertype((long)1);
        garbageRecyclingOrder.setReadmetertype((long)1);
        garbageRecyclingOrder.setCtime(date);
        JiFenJiSuan jiFenJiSuan = new JiFenJiSuan(garbageRecyclingOrder.getDelivertype(),garbageRecyclingOrder.getRecyclingweight());
        garbageRecyclingOrder.setAccpoints(jiFenJiSuan.getJiFen());
        System.out.println("添加垃圾回收订单");



        //给垃圾回收详细订单实体类赋值
        GarbageRecyclingDetailOrder garbageRecyclingDetailOrder = new GarbageRecyclingDetailOrder();
        garbageRecyclingDetailOrder.setAccpoints(jiFenJiSuan.getJiFen());
        garbageRecyclingDetailOrder.setDetailorderid(suiJiId.getDetailOrderId());
        garbageRecyclingDetailOrder.setOrderid(garbageRecyclingOrder.getOrderid());
        garbageRecyclingDetailOrder.setRecyclingtype((long)1);
        garbageRecyclingDetailOrder.setRecyclingweight(garbageRecyclingOrder.getRecyclingweight());
        System.out.println("添加圾回收详细订单");
        System.out.println("所获积分:"+garbageRecyclingOrder.getAccpoints());
        System.out.println("修改设备库存");
        System.out.println("修改用户积分表积分");
        System.out.println("添加总平台积分表数据");
        garbageRecyclingDetailOrderMapper.insertGarbageRecyclingDetailOrder(garbageRecyclingDetailOrder);
        return garbageRecyclingOrderMapper.insertGarbageRecyclingOrder(garbageRecyclingOrder);
    }

    /**
     * 修改垃圾回收订单
     * 
     * @param garbageRecyclingOrder 垃圾回收订单
     * @return 结果
     */
    @Override
    public int updateGarbageRecyclingOrder(GarbageRecyclingOrder garbageRecyclingOrder)
    {
        return garbageRecyclingOrderMapper.updateGarbageRecyclingOrder(garbageRecyclingOrder);
    }

    /**
     * 批量删除垃圾回收订单
     * 
     * @param orderids 需要删除的垃圾回收订单ID
     * @return 结果
     */
    @Override
    public int deleteGarbageRecyclingOrderByIds(Long[] orderids)
    {
        return garbageRecyclingOrderMapper.deleteGarbageRecyclingOrderByIds(orderids);
    }

    /**
     * 删除垃圾回收订单信息
     * 
     * @param orderid 垃圾回收订单ID
     * @return 结果
     */
    @Override
    public int deleteGarbageRecyclingOrderById(Long orderid)
    {
        return garbageRecyclingOrderMapper.deleteGarbageRecyclingOrderById(orderid);
    }
}
